<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="../WEB-INF/facelets/admintemplate.xhtml">
        <ui:define name="admincontent" >
            <div id="admininfo">
                <table>
                    <colgroup>
                        <col />
                        <col />
                        <col />
                    </colgroup>
                    <thead>
                        <tr>
                            <th>
                                User activity
                            </th>
                            <th>
                                Comment activity
                            </th>
                            <th>
                                Image activity
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>
                                <h:form>
                                    <!-- This should only display users who are logged in -->
                                    <p:dataTable var="user" value="#{consoleBackingBean.activeUsers}">
                                        <p:column sortBy="#{user.id}">
                                            <f:facet name="header">
                                                <h:outputText value="Id" />
                                            </f:facet>
                                            <h:outputText value="#{user.id}" />
                                        </p:column>

                                        <p:column sortBy="#{user.username}">
                                            <f:facet name="header">
                                                <h:outputText value="Name" />
                                            </f:facet>
                                            <h:outputText value="#{user.username}" />
                                        </p:column>

                                        <p:column sortBy="#{user.type}">
                                            <f:facet name="header">
                                                <h:outputText value="Role" />
                                            </f:facet>
                                            <h:outputText value="#{user.type}" />
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Remove" />
                                            </f:facet>
                                            <h:commandButton value="Rem" actionListener="#{consoleControls.removeUser}" >
                                                <f:ajax render="@all" />
                                                <f:attribute name="#{consoleBackingBean.userAttName}" value="#{user}" />
                                            </h:commandButton>
                                        </p:column>
                                    </p:dataTable>
                                </h:form>
                            </td>
                            <td>
                                <!--Comment data table-->
                                <h:form>
                                    <!-- This should list recently added comments-->
                                    <p:dataTable var="comment" value="#{consoleBackingBean.newcomments}">
                                        <p:column sortBy="#{comment.id}">
                                            <f:facet name="header">
                                                <h:outputText value="Id" />
                                            </f:facet>
                                            <h:outputText value="#{comment.id}" />
                                        </p:column>

                                        <p:column sortBy="#{comment.user.username}">
                                            <f:facet name="header">
                                                <h:outputText value="User" />
                                            </f:facet>
                                            <h:outputText value="#{comment.user.username}" />
                                        </p:column>

                                        <p:column sortBy="#{comment.commentText}">
                                            <f:facet name="header">
                                                <h:outputText value="Text" />
                                            </f:facet>
                                            <h:outputText value="#{comment.commentText}" />
                                        </p:column>
                                        <p:column sortBy="#{comment.added}">
                                            <f:facet name="header">
                                                <h:outputText value="Written" />
                                            </f:facet>
                                            <h:outputText value="#{comment.added}" >
                                                <f:converter converterId="com.ocpsoft.PrettyTimeConverter"/>
                                            </h:outputText>
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Remove" />
                                            </f:facet>
                                            <h:commandButton value="Rem" actionListener="#{consoleControls.removeComment}" >
                                                <f:ajax render="@all" />
                                                <f:attribute name="#{consoleBackingBean.commentAttName}" value="#{comment}" />
                                            </h:commandButton>
                                        </p:column>
                                    </p:dataTable>
                                </h:form>
                            </td>
                            <td>
                                <!--Image data table-->
                                <h:form>
                                    <!-- This should list newly added images -->
                                    <p:dataTable var="image" value="#{consoleBackingBean.newImages}">
                                        <p:column sortBy="#{image.id}">
                                            <f:facet name="header">
                                                <h:outputText value="Id" />
                                            </f:facet>
                                            <h:outputText value="#{image.id}" />
                                        </p:column>
                                        <p:column sortBy="#{image.user.username}">
                                            <f:facet name="header">
                                                <h:outputText value="Name" />
                                            </f:facet>
                                            <h:outputText value="#{image.user.username}" />
                                        </p:column>
                                        <p:column sortBy="#{image.added}">
                                            <f:facet name="header">
                                                <h:outputText value="Added" />
                                            </f:facet>
                                            <h:outputText value="#{image.added}" >
                                                <f:converter converterId="com.ocpsoft.PrettyTimeConverter"/>
                                            </h:outputText>
                                        </p:column>
                                        <p:column>
                                            <f:facet name="header">
                                                <h:outputText value="Remove" />
                                            </f:facet>
                                            <h:commandButton value="Rem" actionListener="#{consoleControls.removeImage}" >
                                                <f:ajax render="@all" />
                                                <f:attribute name="#{consoleBackingBean.imageAttName}" value="#{image}" />
                                            </h:commandButton>
                                        </p:column>
                                    </p:dataTable>
                                </h:form>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </ui:define>
    </ui:composition>
</html>

